<template>
	<view>
		<view class="login-back" @click="back">
			<uni-icons type="arrowleft" size="20" color="#FFF"></uni-icons>
		</view>
		<view class="login-bg"></view>

		<view class="login">
			<view class="flex">
				<text class="title">绑定手机号</text>
			</view>
			<view class="login-form">
				<uni-icons type="person"></uni-icons>
				<input type="text" placeholder="请输入手机号" v-model="form.phone" />
			</view>
			<view class="login-form">
				<uni-icons type="email"></uni-icons>
				<input type="text" placeholder="请输入验证码" v-model="form.code" />
				<code-btn :phone="form.phone"></code-btn>
			</view>
			<view class="bg-main btn" hover-class="bg-main-hover" @click="submit">绑 定</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					phone: '',
					code: ''
				}
			}
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				});
			},
			submit(){
				uni.showLoading({
					title: '提交中...',
					mask: false
				});
				let data = Object.assign(this.form, {}) // 拷贝一份form对象
				this.$api.postMobileBindMobile(data).then(res=>{
					this.$toast('绑定成功')
					this.$store.dispatch('updateInfo', data.phone)
					setTimeout(()=>{
						this.back()
					},350)
				}).finally(()=>{
					uni.hideLoading()
				})
				
			}
		}
	}
</script>

<style>
	
</style>
